$(function () {//加载表格
    initData();
})


// 初始化加载下拉框的值
function initData() {
    $.ajax({
            type: "post",
            url: finance + "/voucher/init",
            dataType: "json",
            success: function (data) {
                if (successcode != data.code) {
                    return errorHandle(data);
                }
                var lsetlists = data.data.lsetlists;
                if (!isNull(lsetlists)) {
                    $("#accountId").combotree("loadData", lsetlists);
                }
            }, error: function (data) {
                $.messager.progress('close');
                $.messager.alert('系统提示', "系统异常，请稍后重试！", 'error');
            }
        }
    );
}

function produceVoucher() {
    var accountId = getCommbotreeValue("accountId");
    //没有选择 就查询所有的下拉框的
    if (isNull(accountId)) {
        accountId = getCommbotreeAllValue("accountId");
    }
    $.messager.progress({text: '正在处理中...',});
    $.ajax({
            type: "post",
            url: finance + "/voucher/produceVoucher",
            dataType: "json",
            data: {
                selfdate: $("#selfdate").combobox("getValue"),
                accountId: accountId,
                ftype: "STOCK_VOUCHER"
            },
            success: function (data) {
                $.messager.progress('close');
                if (successcode != data.code) {
                    return errorHandle(data);
                }
                $.messager.show({title: '系统提示', msg: data.message});
                $("#dg").datagrid("load");
            }, error: function (data) {
                $.messager.progress('close');
                $.messager.alert('系统提示', "系统异常，请稍后重试！", 'error');
            }
        }
    );
}
